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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
]


  img_x = Iup.Image( 11, 11, pixmap_x ) 
  img_x["1"] = "0 1 0" 
  img_x["2"] = "255 0 0"  
  img_x["3"] = "255 255 0" 

  Iup.SetHandle( "img_x", img_x )
  img_cursor = Iup.Image( 32, 32, pixmap_cursor ) 

  img_cursor["1"] = "255 0 0"   
  img_cursor["2"] = "128 0 0"   

  img_cursor.hotspot = "21:10"  
  
  Iup.SetHandle( "img_cursor", img_cursor )

  btn = Iup.Button( "Dummy") 
  btn.image = "img_x"  

  lbl = Iup.Label( "Dummy" ) 
  lbl.image = "img_x"  

  tgl = Iup.Toggle("Dummy") 
  tgl.image = "img_x"  

  tgl_radio_1 = Iup.Toggle("Dummy") 
  tgl_radio_2 = Iup.Toggle("Dummy") 

  tgl_radio_1.image = "img_x"  
  tgl_radio_2.image = "img_x"  

  string_size =  "\"X\" image width = #{img_x.width} \"X\" image height = #{img_x.height}"  

  lbl_size = Iup.Label( string_size ) 
  
  frm_btn = Iup.Frame( btn ) 
  frm_lbl = Iup.Frame( lbl ) 
  frm_tgl = Iup.Frame( tgl ) 
  frm_tgl_radio = Iup.Frame( Iup.Radio( Iup.Vbox([ tgl_radio_1, tgl_radio_2]) ) ) 

 frm_btn.attr = "TITLE=button, SIZE=EIGHTHxEIGHTH"  
 frm_lbl.attr = "TITLE=label , SIZE=EIGHTHxEIGHTH"  
 frm_tgl.attr = "TITLE=toggle, SIZE=EIGHTHxEIGHTH"  
 frm_tgl_radio.attr = "TITLE=radio, SIZE=EIGHTHxEIGHTH"  
  
  dlg = Iup.Dialog(
          Iup.Vbox([
            Iup.Hbox([ frm_btn, frm_lbl, frm_tgl, frm_tgl_radio]),
            Iup.Fill(),
            Iup.Hbox([ Iup.Fill(), lbl_size, Iup.Fill()])]
          )
        ) 

  dlg.attr = "TITLE=\"Iup.Image Example\", SIZE=HALFxQUARTER, CURSOR=img_cursor"  

  dlg.ShowXY(Iup::CENTER, Iup::CENTER) 

  Iup.MainLoop() 
  dlg.Destroy()
  img_x.Destroy()
  img_cursor.Destroy()
